package com.whfc.fvs.service.impl;

import com.whfc.common.result.ListData;
import com.whfc.common.third.uni.UniApi;
import com.whfc.common.third.uni.entity.CameraPreviewUrlResponse;
import com.whfc.fvs.dao.FvsDeviceMapper;
import com.whfc.fvs.dto.FvsDeviceDTO;
import com.whfc.fvs.dto.FvsRecordDTO;
import com.whfc.fvs.dto.FvsStreamDTO;
import com.whfc.fvs.dto.FvsTokenDTO;
import com.whfc.fvs.enums.FvsDevicePtzOption;
import com.whfc.fvs.param.FvsDeviceAddParam;
import com.whfc.fvs.service.FvsPlatformService;
import com.whfc.fvs.service.UniResourceSyncService;
import com.whfc.fvs.service.factroy.FvsPlatformConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service(FvsPlatformConstant.UNI_SERVER_SERVICE)
public class FvsUniPlatformServiceImpl implements FvsPlatformService {

    @Autowired
    private FvsDeviceMapper fvsDeviceMapper;

    @Autowired
    private UniApi uniApi;


    @Override
    public void addDevice(FvsDeviceDTO fvsDeviceDTO, FvsDeviceAddParam deviceAddParam) {

    }

    @Override
    public void deleteDevice(FvsDeviceDTO fvsDeviceDTO) {

    }

    @Override
    public String getSnapshotUrl(FvsDeviceDTO fvsDeviceDTO) {
        return "";
    }

    @Override
    public FvsStreamDTO getStreamUrl(FvsDeviceDTO fvsDeviceDTO) {
        FvsStreamDTO dto = new FvsStreamDTO();
        CameraPreviewUrlResponse response = uniApi.getCameraPreviewUrl(fvsDeviceDTO.getSn(),2,"rtsp",1);
        if (response != null){
            dto.setPlayUrl(response.getData().getUrl());
            dto.setEzopen(response.getData().getUrl());
            dto.setHls(response.getData().getUrl());
            dto.setEzvizToken(response.getData().getAccessToken());
            return dto;
        }
        return null;
    }

    @Override
    public ListData<FvsRecordDTO> getRecordList(FvsDeviceDTO fvsDeviceDTO, Date startTime, Date endTime) {
        return null;
    }

    @Override
    public void ptz(FvsDeviceDTO fvsDeviceDTO, FvsDevicePtzOption devicePtzOption) {

    }

    @Override
    public FvsTokenDTO getToken(Integer deptId) {
        FvsTokenDTO dto = new FvsTokenDTO();
        CameraPreviewUrlResponse response = uniApi.getCameraPreviewUrl("587413344177095654",2,"rtsp",1);
        if (response != null){
            dto.setToken(response.getData().getAccessToken());
            return dto;
        }
        return null;
    }
}
